<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="lib/webgl-debug.js"></script>
  <script src="lib/webgl-utils.js"></script>
  <script src="lib/cuon-utils.js"></script>
  <script src="lib/cuon-matrix.js"></script>
  <title>webgl使用attribute</title>
</head>
<body onload="main()">
  <canvas id="canvas" width="400" height="400"></canvas>
</body>
<script>
  var vss =`
  attribute vec4 ap;
  attribute vec4 a_Position;
  void main(){
    gl_Position =a_Position;
    gl_PointSize =10.0;
  }
  `
  var fss =`
  void main(){
    gl_FragColor = vec4(0.5,0.0,0.0,1.0);//设置颜色
  }
  `

  function main(){
    var canvas = document.getElementById('canvas');
    //获取webgl的上下文
    var gl = getWebGLContext(canvas);
    // 初始化着色器
    if(!initShaders(gl,vss,fss)){
      console.log("********")
      return;
    }
 
     //获取attribute变量的存储位置
     var a_Position = gl.getAttribLocation(gl.program, "a_Position");
    //设置顶点位置传输给a_Position变量
    gl.vertexAttrib3f(a_Position,0.2,0.3,0.0);
    gl.clearColor(0,0,0,1.0);
    gl.clear(gl.COLOR_BUFFER_BIT);
    gl.drawArrays(gl.POINTS,0,1);
  }
</script>
</html>